import {FirstUpperCase} from '../../utils/formatterString';
export default option => {
  let {
    data,
  } = option;
  let dataStep = {};
  for (let dialogRef in data) {
    if (data.hasOwnProperty(dialogRef) && /^dialog/.test(dialogRef)) {
      let step = Object.assign({
        visible: false,
      }, data[dialogRef]);
      data[dialogRef] = {
        width: '50%',
        top: '15vh',
        ref: dialogRef,
        fullscreen: false,
        visible: false,
        formRef: true,
        isPorp: false,
        modal: true,
        // dialogCallBack: function () {},
        dialogInit: function (cb) {
          this[dialogRef] = {
            ...this[dialogRef],
            ...step,
          };
          if (this[dialogRef].formRef) {
            if (this[dialogRef].formRef.constructor === Array) {
              this[dialogRef].formRef.forEach(item => {
                this.resetFields(item);
              });
            } else if (this[dialogRef].formRef.constructor === String) {
              this.resetFields(this[dialogRef].formRef);
            } else {
              this.resetFields('form' + FirstUpperCase(dialogRef));
            }
          }
          if (cb && cb.constructor === Function) {
            cb.call(this);
          } else if (this[dialogRef].dialogCallBack && this[dialogRef].dialogCallBack.constructor === Function) {
            this[dialogRef].dialogCallBack.call(this);
          }
        },
        ...data[dialogRef],
      };
    }
  }
  option.data = {
    ...option.data,
    ...dataStep,
  };
};
